#include "BaseBot.h"
#include "ASprite.h"
#include "Game.h"


BaseBot::BaseBot()
{
	SetObjectType(Object_BaseBot);	

	m_timerShowShield = ActiveTimer();
	SetEnabled(true);
	SetRenderable(true);
}
	
BaseBot::~BaseBot()
{
}

void BaseBot::SaveData(CWriteFile* stream)
{
	GameObject::SaveData(stream);

	
}
void BaseBot::LoadData(CReadFile* stream)
{
	GameObject::LoadData(stream);
	
}

void BaseBot::Initialize()
{
	SetPosition(100,450);
	m_radius = 100;

	

	InitPhysics();
}


void BaseBot::InitPhysics()
{	
	{
		b2CircleDef circleDef;
		circleDef.radius = 0.6f;
		circleDef.density = 0.0f;
		circleDef.restitution = 0.0f;
		circleDef.friction = 0;



		b2BodyDef bd;
		bd.allowSleep = false;
		bd.position.Set(0.5f, 0.3f);
		bd.gravityFactor  =0.0f;
		m_physicsBody = GetGameObjectManager()->GetPhysicsWorld().CreateBody(&bd);
		
		m_physicsBody->CreateShape(&circleDef);
		m_physicsBody->SetMassFromShapes();

		m_physicsBody->SetUserData( this );
	}
}

bool BaseBot::ShouldCollideWith( GameObject* h )
{
	if(h && h->GetObjectType() == Object_ThrowableObj)
	{
		return true;
	}

	return false;
}
void BaseBot::ShowSheild()
{
	m_timerShowShield.SetTime(300);
}
void BaseBot::TakeDamage(int damage)
{
	
}
void BaseBot::Draw()
{
	if(m_timerShowShield.IsActive())
	{
		getGfx()->SetColor(0xff00ffff);	
		//getGfx()->DrawCircle2(m_position.X,m_position.Y,m_radius);
	}
}

void BaseBot::Update()
{
	if(m_timerShowShield.IsActive())
	{
		if(m_timerShowShield.IsDone())
		{
			m_timerShowShield.SetTime(0);
		}
		else
			m_timerShowShield.Update(TIME_STEP);
		
	}
}

void BaseBot::LoadParams(IAttributes* attr)
{
	m_objectID = attr->getAttributeAsInt("Id");
	Load(attr);
}
